package com.yuanfeng.action.admin.admin.dao;
import java.util.List;
import com.yuanfeng.pojo.Admins;
import com.yuanfeng.util.MD5Util;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
 * 后台用户模块
 */
public class AdminDaoImpl extends HibernateDaoSupport implements AdminDao{
	/**
	 * 注册用户
	 * @param admins
	 */
	@Override
	public void regsiterAdmins(Admins admins) {

		Admins admins_ = new Admins();
		admins_.setId("A006");
		admins_.setName(admins.getName());
		admins_.setPassword(MD5Util.md5(admins.getPassword()));
		admins_.setEmail(admins.getEmail());
		admins_.setDescr(admins.getDescr());
		this.getHibernateTemplate().save(admins_);
	}

	/**
	 * 通过名字查找
	 * @param name
	 * @return
	 */
	public Admins queryByName(String name){

		Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("from Admins where name=?");
		List<Admins> admins = query.setParameter(0, name).list();
		return admins.get(0);

	}

}
